package com.lcm.jnode.controller.admin;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.lcm.jnode.interceptor.AdminInterceptor;
import com.lcm.jnode.model.DataTablesModel;
import com.lcm.jnode.model.Links;

/**
 * 网站设置
 * @author L.cm
 * @date 2013-6-4 上午10:16:14
 */
@Before(AdminInterceptor.class)
public class AdminLinksController extends Controller {
    
    /**
     * 网站链接
     * @param     设定文件
     * @return void    返回类型
     * @throws
     */
    public void index() {}
    
    /**
     * 后台 链接 列表
     * @param     设定文件
     * @return void    返回类型
     * @throws
     */
    public void list_json() {
        int iDisplayStart = getParaToInt("iDisplayStart", 0);
        int iDisplayLength = getParaToInt("iDisplayLength", 10);
        int pageNum =  iDisplayStart / iDisplayLength + 1;
        String sEcho = getPara("sEcho", "1");
    	String select = "SELECT b.id, b.title, b.blog_type, b.del_status, u.nick_name, b.update_time";
    	String sqlExceptSelect = "FROM blog AS b ,user_info AS u ORDER BY b.id DESC";
    	DataTablesModel dataTable = Links.dao.paginateDataTables(pageNum, 
    	        iDisplayLength, select, sqlExceptSelect, sEcho);
        renderJson(dataTable);
    }
    
    /**
     * 跟新网站友链
     * @Title: save_update
     * @param     设定文件
     * @return void    返回类型
     * @throws
     */
    public void save_update(){
    	Links links = getModel(Links.class);
		boolean state = false;
		if(null == links.getInt(Links.ID)){
			state = links.save();
		} else {
			state = links.update();
		}
		renderJson("state", state);
    }
}
